package logic

import (
	"bw-renting/model/mysql"
	"bw-renting/user-rpc/internal/svc"
	"bw-renting/user-rpc/user"
	"context"
	"log"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserLoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLoginLogic {
	return &UserLoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// Todo:用户名登录
func (l *UserLoginLogic) UserLogin(in *user.UserLoginReq) (*user.Response, error) {
	// todo: add your logic here and delete this line
	mobile := in.Username
	err, id, pass := mysql.UserLogin(mobile)
	log.Println(id, pass)
	if err == false {
		return &user.Response{
			Code:    -1,
			Message: "手机号不存在",
		}, nil
	}

	if pass != in.Password {
		return &user.Response{
			Code:    -1,
			Message: "密码错误",
			UserId:  int64(id),
		}, nil
	}
	return &user.Response{
		Code:    200,
		Message: "",
		UserId:  int64(id),
	}, nil
}
